/***
 * Excerpted from "OpenGL ES for Android",
 * published by The Pragmatic Bookshelf.
 * Copyrights apply to this code. It may not be used to create training material, 
 * courses, books, articles, and the like. Contact us if you are in doubt.
 * We make no guarantees that this code is fit for any purpose. 
 * Visit http://www.pragmaticprogrammer.com/titles/kbogla for more book information.
***/
package openGl;

import android.opengl.GLES20;

import java.nio.FloatBuffer;

import camera.OpenGl.utils.ByteBufferUtils;
import openGl.utils.ColorShaderProgram;

import static android.opengl.GLES20.GL_POINTS;
import static android.opengl.GLES20.glDrawArrays;

public class Mallet {
    private static final int POSITION_COMPONENT_COUNT = 2;
    private static final int COLOR_COMPONENT_COUNT = 3;
    private static final int STRIDE = 
        (POSITION_COMPONENT_COUNT + COLOR_COMPONENT_COUNT) 
        * 4;
    private static final float[] VERTEX_DATA = {
        // Order of coordinates: X, Y, R, G, B
        0f, -0.4f, 0f, 0f, 1f, 
        0f,  0.4f, 1f, 0f, 0f };
   
    private FloatBuffer malletData;
    public Mallet(ColorShaderProgram colorProgram) {
        malletData= ByteBufferUtils.makeFloteByteBuffer(VERTEX_DATA);
       bindData(colorProgram);
    }
    
    public void bindData(ColorShaderProgram colorProgram) {
//        vertexArray.setVertexAttribPointer(
//            0,
//            colorProgram.getPositionAttributeLocation(),
//            POSITION_COMPONENT_COUNT, 
//            STRIDE);
//        vertexArray.setVertexAttribPointer(
//            POSITION_COMPONENT_COUNT,
//            colorProgram.getColorAttributeLocation(), 
//            COLOR_COMPONENT_COUNT,
//            STRIDE);
        GLES20.glEnableVertexAttribArray(colorProgram.aPosition);
        malletData.position(0);
        GLES20.glVertexAttribPointer(colorProgram.aPosition,2,
                GLES20.GL_FLOAT,false,20,malletData);

        GLES20.glEnableVertexAttribArray(colorProgram.aColor);
        malletData.position(2);
        GLES20.glVertexAttribPointer(colorProgram.aColor,3,
                GLES20.GL_FLOAT,false,20,malletData);
       
    }

    public void draw() {        
        glDrawArrays(GL_POINTS, 0, 2);
    }
}
